package com.wsk.controller;

import com.wsk.bean.UserInformation;
import com.wsk.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
public class UserController {
    @Autowired
    private LoginService loginService;
    @RequestMapping("save")
    @ResponseBody
    public UserInformation save(){
        List list = new ArrayList<>();
        UserInformation userInformation = new UserInformation();
        userInformation.setName("wsk");
        userInformation.setPhone("123");
        userInformation.setBuildtime(new Date());
        if (loginService.save(userInformation))
            list.add("success");
        else
            list.add("fail");
        return userInformation;
    }
    @RequestMapping("/wsk")
    public String delete(@RequestParam(value = "test")String test, Model model){
        test = "从哪里来，回哪里去";
        model.addAttribute("test", test);
        return "test";
    }
    @RequestMapping("/find")
    @ResponseBody
    public com.wsk.bean2.UserInformation find(@RequestParam(value = "id")int id){
        return loginService.getUserInformation(id);
    }
}
